import type {BatchImportExportConfigForm} from "@/api/batchImportExportConfig/model";
import BatchImportExportConfigAPI from "@/api/batchImportExportConfig/index";
import type {IModalConfig} from "@/components/PageModal/index.vue";


const modalConfig = (params?: any): IModalConfig<BatchImportExportConfigForm> => {
    return {
        pageName: "batchImportExportConfig",
        dialog: {
            title: "新增数据导入导出管理",

            draggable: true,
        },

        formAction: BatchImportExportConfigAPI.add,
        beforeSubmit(data) {
            //提交之前处理
        },
        formItems: [
            {
                label: "表名",
                prop: "tableName",
                type: "select",
                attrs: {
                    placeholder: "请选择表名",
                    filterable: true,
                },
                rules: [{required: true, message: "表名不能为空", trigger: "blur"}],
                async initFn(formItem) {
                    this.options = await params?.getAllTableInfo();
                },
            },
            {
                label: "备注信息",
                prop: "remark",
                type: "input",
                attrs: {
                    placeholder: "请输入备注信息",
                },
            },
            {
                label: "模板类型",
                prop: "type",
                rules: [{required: true, message: "模板类型不能为空", trigger: "blur"}],
                type: "radio",
                options: [
                    {label: "导入", value: "0"},
                    {label: "导出", value: "1"},
                ],
                attrs: {
                    placeholder: "请选择模板类型",
                },
                initialValue: '0',
                watch(newValue, oldValue, data, items) {
                    const importTypeProp = items.find((item) => item.prop === "importType");
                    if (newValue === "0") {
                        importTypeProp.hidden = false;
                    } else {
                        importTypeProp.hidden = true;
                    }
                },
            },
            {
                label: "导入类型",
                prop: "importType",
                rules: [{required: true, message: "导入类型不能为空", trigger: "blur"}],
                type: "radio",
                options: [
                    {label: "增量导入", value: "0"},
                    {label: "全量导入（先删后插）", value: "1"},
                ],
                attrs: {
                    placeholder: "请选择导入类型",
                },
                initialValue: '0'
            },
        ],
    }
};
export default modalConfig;